package com.cqs.leetcode.array;

/**
 * lixw
 * 2021/11/8
 **/
public class BullsCows299 {

    public String getHint(String secret, String guess) {
        int[] scnt = new int[10];
        int[] gcnt = new int[10];
        for (int i = 0; i < secret.length(); i++) {
            scnt[secret.charAt(i) - '0']++;
        }
        for (int i = 0; i < guess.length(); i++) {
            gcnt[guess.charAt(i) - '0']++;
        }
        int sum = 0, bulls = 0;
        for (int i = 0; i < 10; i++) {
            sum += Math.min(scnt[i], gcnt[i]);
        }
        for (int i = 0; i < secret.length() && i < guess.length(); i++) {
            if (secret.charAt(i) == guess.charAt(i)) bulls++;
        }
        return bulls + "A" + (sum - bulls) + "B";
    }
}
